package com.tdr.myandroid.model;

import java.util.ArrayList;

/**
 * Created by Administrator on 2014/7/17.
 */
public class EventsManger {
    private static EventsManger mgr = null;
    private ArrayList<EventObject> events;
    private ArrayList<ConditionObject> conditions;

    public static synchronized EventsManger getMgr() {
        if (mgr == null) {
            mgr = new EventsManger();
        }
        return mgr;
    }
    public ArrayList<EventObject> getEvents() {
        return events;
    }
    public void addEvent(EventObject newEvent) {
        if (newEvent != null) {
            events.add(newEvent);
        }
    }
    public void addCondition(ConditionObject newCondition) {
        if (newCondition != null) {
            conditions.add(newCondition);
        }
    }

    public boolean hasReachedCondition() {
        return (conditions.size() != 0);
    }

    public boolean matchEvent(EventObject event) {
        boolean found = false;

        for (ConditionObject condition : conditions) {
            if (event.matchCondition(condition)) {
                found = true;
                break;
            }
        }
        return found;
    }
}
